<template>
  <div>
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()">
      <el-form-item>
        <el-input v-model="dataForm.userId" placeholder="uid"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.nickname" placeholder="昵称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.id" placeholder="心愿单编号"></el-input>
      </el-form-item>
      <el-form-item label="心愿类型：">
        <el-select v-model="dataForm.wishType" placeholder="请选择">
          <el-option
            v-for="item in useroption"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="search()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;"
    >
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="userId" header-align="center" align="center" label="uid"></el-table-column>
      <el-table-column prop="nickname" header-align="center" align="center" label="昵称"></el-table-column>
      <el-table-column prop="avatar" header-align="center" align="center" label="头像">
        <template slot-scope="scope">
          <img :src="scope.row.avatar" style="width:40px;height:40px;">
        </template>
      </el-table-column>
      <el-table-column prop="credit" header-align="center" align="center" label="捐献积分"></el-table-column>
      <el-table-column prop="partnerName" header-align="center" align="center" label="捐献对象"></el-table-column>
      <el-table-column prop="partnerId" header-align="center" align="center" label="捐助对象编号"></el-table-column>
      <el-table-column prop="id" header-align="center" align="center" label="心愿单编号"></el-table-column>
      <el-table-column header-align="center" align="center" label="心愿类型">
        <template slot-scope="scope">
          {{ scope.row.wishType === 1?'个人心愿':'' }}
          {{ scope.row.wishType === 2?'团队心愿':'' }}
        </template>
      </el-table-column>
      <el-table-column prop="gmtUpdate" header-align="center" align="center" label="时间"></el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
  </div>
</template>
<style>
.active {
  color: #f00;
}
</style>
<script>
export default {
  data() {
    return {
      dataForm: {
        key: "",
        userId: "",
        id: "",
        nickname: ""
      },
      useroption: [
        {
          value: null,
          label: '全部'
        },
        {
          value: '1',
          label: '个人心愿'
        },
        {
          value: '2',
          label: '团队心愿'
        }
      ],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: []
    };
  },
  activated() {
    this.getDataList();
  },
  methods: {
    search() {
      this.pageIndex = 1
      this.getDataList()
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let obj = {
        page: this.pageIndex,
        limit: this.pageSize,
        key: this.dataForm.key
      }
      if (this.dataForm.wishType) {
        obj.wishType = this.dataForm.wishType;
      }
      if (this.dataForm.id) {
        obj.id = this.dataForm.id;
      }
      if (this.dataForm.nickname) {
        obj.nickname = this.dataForm.nickname;
      }
      if (this.dataForm.userId) {
        obj.userId = this.dataForm.userId;
      }
      this.$http({
        url: this.$http.adornUrl("/partner/userwishdonate/list"),
        method: "get",
        params: this.$http.adornParams(obj)
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
  }
};
</script>
